$settingsDir = "$env:USERPROFILE\.m2"
if (-not (Test-Path $settingsDir)) {
    New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null
}

$xml = New-Object System.Xml.XmlDocument
$declaration = $xml.CreateXmlDeclaration("1.0", "UTF-8", $null)
$xml.AppendChild($declaration) | Out-Null

$settings = $xml.CreateElement("settings")
$settings.SetAttribute("xmlns", "http://maven.apache.org/SETTINGS/1.0.0")
$settings.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
$settings.SetAttribute("xsi:schemaLocation", "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd")
$xml.AppendChild($settings) | Out-Null

$mirrors = $xml.CreateElement("mirrors")
$settings.AppendChild($mirrors) | Out-Null

$mirror = $xml.CreateElement("mirror")
$mirrors.AppendChild($mirror) | Out-Null

$id = $xml.CreateElement("id")
$id.InnerText = "aliyunmaven"
$mirror.AppendChild($id) | Out-Null

$mirrorOf = $xml.CreateElement("mirrorOf")
$mirrorOf.InnerText = "central"
$mirror.AppendChild($mirrorOf) | Out-Null

$name = $xml.CreateElement("name")
$name.InnerText = "阿里云公共仓库"
$mirror.AppendChild($name) | Out-Null

$url = $xml.CreateElement("url")
$url.InnerText = "https://maven.aliyun.com/repository/public"
$mirror.AppendChild($url) | Out-Null

$settingsPath = "$settingsDir\settings.xml"
$xml.Save($settingsPath)

Write-Host "Maven配置文件已创建: $settingsPath" 